using System;
using NUnit.Framework;
using WWB.DisqusSharp.Model;
using WWB.DisqusSharp.Model.DisqusDTO;
using WWB.DisqusSharp.Model.DisqusService;

namespace WWB.DisqusSharp.Tests.ModelSerialization
{
    [TestFixture]
    [Category("Unit Tests")]
    public class ForumsPayloadTest
    {
        private IDisqusServiceResult<Forum[]> resultBase;

        [TestFixtureSetUp]
        public void ArrangeAndAct()
        {
            string json =
                "{\"message\": [{\"created_at\": \"2010-08-12 13:44:35.983096\", \"shortname\": \"cableintheclassroom\", \"description\": \"\", \"id\": \"438500\", \"name\": \"Cable In the Classroom\"}], \"code\": \"ok\", \"succeeded\": true}";

            resultBase = new DisqusServiceResultWrapper<Forum[]>(json);
        }

        [Test]
        public void Result_is_not_null()
        {
            Assert.That(resultBase, Is.Not.Null);
        }

        [Test]
        public void Result_has_expected_scalars()
        {
            Assert.That(resultBase.Error, Is.Null);
            Assert.That(resultBase.IsSuccessful);
        }

        [Test]
        public void Result_message_is_correct()
        {
            Assert.That(resultBase.Payload, Is.Not.Null);
            Assert.That(resultBase.Payload.Length, Is.EqualTo(1));
            var f = resultBase.Payload[0];
            Assert.That(f.Id, Is.EqualTo("438500"));
            Assert.That(f.Name, Is.EqualTo("Cable In the Classroom"));
            Assert.That(f.ShortName, Is.EqualTo("cableintheclassroom"));
            Assert.That(f.CreatedAt,
                        Is.GreaterThan(DateTime.Parse("8/12/2010 13:44:35")).And.LessThan(
                            DateTime.Parse("8/12/2010 13:44:36")));
        }
    }
}